﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;

namespace Framework
{
    public abstract class TextElement : Base
    {
        static TextElement()
        {
            RegisterType(typeof(TextElement));

            RegisterProp(typeof(TextElement), "FontSize", typeof(double), 12.0);
            RegisterProp(typeof(TextElement), "FontFamily", typeof(FontFamily), null);
            RegisterProp(typeof(TextElement), "FontWeight", typeof(FontWeight), null);
            RegisterProp(typeof(TextElement), "FontStyle", typeof(FontStyle), null);
            RegisterProp(typeof(TextElement), "FontStretch", typeof(FontStretch), null);
            RegisterProp(typeof(TextElement), "Foreground", typeof(Brush), null);
            RegisterProp(typeof(TextElement), "Name", typeof(string), null);
            RegisterProp(typeof(TextElement), "Language", typeof(Language), null);
            RegisterProp(typeof(TextElement), "ContentStart", typeof(TextPointer), null);
            RegisterProp(typeof(TextElement), "ContentEnd", typeof(TextPointer), null);
            RegisterProp(typeof(TextElement), "ElementStart", typeof(TextPointer), null);
            RegisterProp(typeof(TextElement), "ElementEnd", typeof(TextPointer), null);
        }
    }

    public class FontSource
    {
        public FontSource(Stream stream) { ; }
    }

    public sealed class Glyphs : UIElement
    {
        static Glyphs()
        {
            RegisterType(typeof(Glyphs), typeof(UIElement));
            RegisterProp(typeof(Glyphs), "UnicodeString", typeof(String), null);
            RegisterProp(typeof(Glyphs), "Indices", typeof(String), null);
            RegisterProp(typeof(Glyphs), "FontUri", typeof(Uri), null);
            RegisterProp(typeof(Glyphs), "StyleSimulations", typeof(StyleSimulations), null);
            RegisterProp(typeof(Glyphs), "FontRenderingEmSize", typeof(Double), null);
            RegisterProp(typeof(Glyphs), "OriginX", typeof(Double), null);
            RegisterProp(typeof(Glyphs), "OriginY", typeof(Double), null);
            RegisterProp(typeof(Glyphs), "Fill", typeof(Brush), null);
            RegisterProp(typeof(Glyphs), "FontSource", typeof(FontSource), null);
        }
    }

    public class Inline : TextElement
    {
        static Inline()
        {
            RegisterType(typeof(Inline), typeof(TextElement));
            RegisterProp(typeof(Inline), "Language", typeof(Language), null);
            RegisterProp(typeof(Inline), "FontSize", typeof(double), null);
            RegisterProp(typeof(Inline), "FontFamily", typeof(FontFamily), null);
            RegisterProp(typeof(Inline), "FontWeight", typeof(FontWeight), null);
            RegisterProp(typeof(Inline), "FontStyle", typeof(FontStyle), null);
            RegisterProp(typeof(Inline), "FontStrecth", typeof(FontStretch), null);
            RegisterProp(typeof(Inline), "Foreground", typeof(Brush), null);
        }

        public Inline() {;}
    }

    public sealed class InlineUIContainer : Inline
    {
        static InlineUIContainer()
        {
            RegisterType(typeof(InlineUIContainer), typeof(Inline));
            RegisterProp(typeof(InlineUIContainer), "Child", typeof(UIElement), null );
        }

        public InlineUIContainer() { ; }
    }

    public sealed class LineBreak : Inline { }

    public sealed class Run : Inline
    {
        static Run()
        {
            RegisterType(typeof(Run),typeof(Inline));
            RegisterProp(typeof(Run), "FlowDirection", typeof(FlowDirection), FlowDirection.LeftToRight);
        }

        public string Text;
        
        public Run() { ; }
    }

    public class Span : Inline
    {
        public Collection<Inline> Inlines { get; set; }
    }

    public sealed class Underline : Span { }

    public sealed class Italic : Span { }

    public sealed class Bold : Span { }

    public sealed class Hyperlink : Span
    {
        static Hyperlink()
        {
            RegisterType(typeof(Hyperlink), typeof(Span));
            RegisterProp(typeof(Hyperlink), "TargetName", typeof(String), null);
            RegisterProp(typeof(Hyperlink), "NavigateUri", typeof(Uri), null);
            RegisterProp(typeof(Hyperlink), "MouseOverForeground", typeof(Brush), null);
            RegisterProp(typeof(Hyperlink), "MouseOverTextDecorations", typeof(bool), null);
            RegisterProp(typeof(Hyperlink), "CommandParameter", typeof(Object), null);
        }
    }

    public abstract class Block : TextElement
    {
        static Block()
        {
            RegisterType(typeof(Block), typeof(TextElement));
            RegisterProp(typeof(Block), "TextAlignment", typeof(TextAlignment), null);
        }
    }

    public sealed class Paragraph : Block
    {
        public Collection<Inline> Inlines { get; set; }
    }

    public sealed class Section : Block
    {
        public Collection<Block> Blocks { get; set; }
        public Boolean HasTrailingParagraphBreakOnPaste { get; set; }
    }

    public class TextPointer
    {
        public LogicalDirection LogicalDirection;
        public object Parent;
        public Boolean IsAtInsertionPosition;
        public object RichTextBox;
        public Int32 Offset;

        public int CompareTo(TextPointer position)
        {
            throw new NotImplementedException();
        }
        public Rect GetCharacterRect(LogicalDirection direction)
        {
            throw new NotImplementedException();
        }
        public TextPointer GetNextInsertionPosition(LogicalDirection direction)
        {
            throw new NotImplementedException();
        }
        public TextPointer GetPositionAtOffset(Int32 offset, LogicalDirection direction)
        {
            throw new NotImplementedException();
        }

    }

    public sealed class TextSelection
    {

        public String Text { get; set; }
        public String Xaml { get; set; }
        public TextPointer Start { get; set; }
        public TextPointer End { get; set; }

        public void ApplyPropertyValue(int formattingProperty, Object value)
        {
            throw new NotImplementedException();
        }

        public Object GetPropertyValue(int formattingProperty)
        {
            throw new NotImplementedException();
        }

        public void Insert(TextElement element)
        {
            throw new NotImplementedException();
        }

        public void Select(TextPointer anchorPosition, TextPointer movingPosition)
        {
            throw new NotImplementedException();
        }

    }

    public enum LogicalDirection
    {
        Backward,
        Forwar
    }

    public enum FlowDirection
    {
        LeftToRight,
        RightToLef
    }

    public enum TextAlignment
    {
        Center,
        Left,
        Right
    }

    public enum TextTrimming
    {
        None,
        WordEllipsi
    }

    public enum StyleSimulations
    {
        None,
        BoldSimulation,
        ItalicSimulation,
        BoldItalicSimulation
    }

}
